<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="
      () => {
        this.visible = false
      }
    "
  >
    <a-table
      ref="table"
      :scroll="{ y: scroll }"
      :columns="columns"
      :rowKey="(row, index) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: type }"
      :bordered="true"
      size="small"
    >
      <template slot="dataIndex" slot-scope="text, record, index">
        <span>{{ (pagination.current - 1) * pagination.pageSize + index + 1 }}</span>
      </template>
    </a-table>
  </a-modal>
</template>

<script>
export default {
  props: {
    title: { type: String, default: '选择人员' },
    type: { type: String, default: 'checkbox' },
  },
  data() {
    return {
      data: [],
      visible: false,
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      pagination: {
        current: 1,
        pageSize: 25,
        pageSizeOptions: ['25', '50', '100'],
        showSizeChanger: true,
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize),
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
      },
      queryParam: {},
    }
  },
  methods: {
    openForm() {
      this.selectedRowKeys = []
      this.selectedRows = []
      this.pagination.current = 1
      this.visible = true
      this.getDataList()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleSubmit() {},
    getDataList() {
      this.$http
        .post('/Base_Manage/Base_User/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Total
          this.pagination = pagination
        })
    },
  },
}
</script>

<style>
</style>